package com.zyp.test;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args) {
        Server server = new Server();
        server.serverstat();
    }

    public void serverstat(){
        Socket socket;
        try {
            ServerSocket serverSocket = new ServerSocket(9999);
            System.out.println("start server in 9999...");
            socket = serverSocket.accept();
            handleconn(socket);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void handleconn(Socket socket) {
        System.out.println("a conn come...");
        try {
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("hello".getBytes());
            outputStream.flush();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
